#define _CRT_SECURE_NO_WARNINGS	1
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int left = 0, right = 0; int n = nums.size();
        int tmp = k, ret = 0;
        while (right < n)
        {
            while (nums[right] == 1)
            {
                right++;
            }
            if (tmp > 0 && nums[right] == 0)
            {
                tmp--;
                right++;
            }
            ret = max(ret, right - left + 1);
            left = right;
        }
        return ret;
    }
};